# -*- coding: utf-8 -*-
'''
把指定页面上的数据结构转换成SQL DDL
'''

mapping={
    'SellerAuthorize':[{'pk':'sid','type':'session'}],
    'ItemCat':[{'pk':'cid','type':'self'}],
    'Brand':[{'pk':'vid','type':'self'}],
    'ItemProp':{'pk':'pid','type':'self'},
    'PropValue':[{'pk':'vid','type':'self'}],
    'ShopCat':[{'pk':'cid','type':'self'}],
    'Feature':[{'pk':'cid','type':'parent'},{'pk':'attr_key','type':'self'}],
    'User':[{'pk':'uid','type':'self'}],
    'UserCredit':[{'pk':'uid','type':'parent'},{'pk':'type','type':'parent'}],
    'Location':[{'pk':'uid','type':'parent'},{'pk':'num_iid','type':'parent'}],
    'AfterSale':[{'pk':'after_sale_id','type':'self'}],
    'ItemTemplate':[{'pk':'template_id'}],
    'Sku':[{'pk':'sku_id','type':'self'}],
    'Item':[{'pk':'num_iid','type':'self'}],
    #'Location':[{'pk':'num_iid','type':'parent'}],
    'ItemImg':[{'pk':'id','type':'self'}],
    'PropImg':[{'pk':'id','type':'self'}],
    'Video':[{'pk':'id','type':'self'}],
    'ItemCategory':[{'pk':'category_id','type':'self'}],
    'Product':[{'pk':'product_id','type':'self'}],
    'ProductImg':[{'pk':'id','type':'self'}],
    'ProductPropImg':[{'pk':'id','type':'self'}],
    'Shop':[{'pk':'sid','type':'self'}],
    'ShopScore':[{'pk':'sid','type':'parent'}],
    'SellerCat':[{'pk':'nick','type':'param'}],
    'Trade':[{'pk':'tid','type':'self'}],
    'Order':[{'pk':'oid','type':'self'}],
    'PromotionDetail':[{'pk':'id','type':'self'}],
    'TradeRate':[{'pk':'tid','type':'self'},{'pk':'oid','type':'self'}]
}

import MySQLdb

def getConn():
    return MySQLdb.connect(host='localhost',
        user='cooper',passwd='1234',
        db='taobaoapi',charset='utf8')

def main():
    db=getConn()
    db.query("SELECT DISTINCT(TYPE) FROM REQRESFORMAT WHERE LEVELTYPE='res_params'")
    r=db.store_result()
    tbs=list()
    for i in range(r.num_rows()):
        tbs.append(r.fetch_row()[0][0].rstrip('[]'))


if __name__ == '__main__':
    main()